package com.hankol.feature_wine_meal.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.PagerAdapter
import com.baselibrary.Constants
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.ARouterUtils
import com.hankol.feature_wine_meal.R
import com.hankol.feature_wine_meal.bean.CuisineRefreshBean

/**
 * @descriptiont 特色菜系tab
 * @author 关忆北、
 * @time 2022/7/11 3:04 下午
 */
class CuisineTabVpAdapter(var listener: OnTabClickListener) : PagerAdapter() {
    private var selectedPos = 0
    private var sourceBannerListBean: ArrayList<String> = arrayListOf()
    fun setData(sourceBannerListBean: ArrayList<String>) {
        this.sourceBannerListBean.clear()
        this.sourceBannerListBean.addAll(sourceBannerListBean)
        notifyDataSetChanged()
    }

    @SuppressLint("SetTextI18n")
    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val inflate = LayoutInflater.from(container.context).inflate(R.layout.item_cuisine_tab_tv, container, false)
        val tabText = inflate.findViewById<TextView>(R.id.tv_cuisine_tab_text)
        tabText.text = sourceBannerListBean[position]
        if (selectedPos == position) {
            tabText.textSize = 18f
            tabText.setTextColor(ContextCompat.getColor(container.context, R.color.color_333333))
        } else {
            tabText.textSize = 14f
            tabText.setTextColor(ContextCompat.getColor(container.context, R.color.color_999999))

        }

        inflate.setOnClickListener {
            listener.onTabClick(position)
        }

        container.addView(inflate)
        return inflate
    }

    override fun getCount(): Int {
        return sourceBannerListBean.size
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object`
    }

    override fun destroyItem(container: ViewGroup, position: Int, view: Any) {
        container.removeView(view as View)
    }

    override fun getItemPosition(`object`: Any): Int {
        return POSITION_NONE
    }

    interface OnTabClickListener {
        fun onTabClick(position: Int)
    }
}